package com.zhang.queue;

/**
 * @author zhang
 * @time 2022/03/07 21:36:00
 */
public class PriorityQueue {
    private int[] items = new int[5];
    private int count;

    public void add(int item) {
        if (isFull()) {
            throw new IllegalStateException();
        }
        int i = shiftItemToInsert(item);
        items[i] = item;
        count++;

    }

    private int shiftItemToInsert(int item) {
        int i;
        for ( i = count-1; i >= 0 ; i--) {
            if (item < items[i]) {
                items[i + 1] = items[i];
            } else {
                break;
            }

        }
        return i + 1;
    }
    private boolean isFull() {
        return count == items.length;
    }
    private boolean isEmpty() {
        return count == 0;
    }
}
